package com.tao.service;

import com.tao.async.MemberServiceAsync;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class MemberService {
    @Autowired
    private MemberServiceAsync memberServiceAsync;

    @RequestMapping("/addMember")
    public String addMember(){
        log.info(">01<");

//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                sms();
//            }
//        }).start();

//        sms();

        memberServiceAsync.sms();

        log.info(">04<");
        return "用户注册成功";
    }

//    @Async
//    public String sms(){
//        log.info(">02<");
//        try {
//            log.info("正在发送短信...");
//            Thread.sleep(1000);
//        }catch (Exception e){
//
//        }
//        log.info(">03<");
//        return "短信发送完毕";
//    }

    @RequestMapping("/insertAge")
    public int insertAge(int age){
        int j = 1/age;
        return j;
    }

}
